﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/MainTemplate.Master" AutoEventWireup="true" CodeBehind="Term.aspx.cs" Inherits="Enterprise.Admin.Term" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <table id="table_list"></table>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="WindowsContent" runat="server">
    <div id="search">
        <form id="search_form" action="Handle/Term/GetListJson.aspx" method="post">
            <p>
                <label>名称：</label><input type="text" class="input_text input_title" name="CoName" />
            </p>
        </form>
    </div>
    <div id="add">
        <form id="add_form" action="Handle/Term/Add.aspx" method="post">
            <p>
                <label>名称：</label><input type="text" class="input_text input_title" name="CoName" />
            </p>
            <p class="en-us">
                <label>名称(En)：</label><input type="text" class="input_text input_title" name="CoNameEn" />
            </p>
            <p>
                <label>排序：</label><input type="text" class="input_text input_title" name="CoSort" value="" />
            </p>
            <p>
                <label style="height: 130px; line-height: 130px;">说明：</label><textarea rows="5" cols="30" name="CoContent"></textarea>
            </p>
            <p class="en-us">
                <label style="height: 130px; line-height: 130px;">说明(En)：</label><textarea rows="5" cols="30" name="CoContentEn"></textarea>
            </p>
        </form>
    </div>
    <div id="edit">
        <form id="edit_form" action="Handle/Term/Edit.aspx" method="post">
            <p>
                <label>名称：</label><input type="text" class="input_text input_title" name="CoName" />
                <input type="hidden" name="CoTermId" value="" />
            </p>
            <p class="en-us">
                <label>名称(En)：</label><input type="text" class="input_text input_title" name="CoNameEn" />
            </p>
            <p>
                <label>排序：</label><input type="text" class="input_text input_title" name="CoSort" value="" />
            </p>
            <p>
                <label style="height: 130px; line-height: 130px;">说明：</label><textarea rows="5" cols="30" name="CoContent"></textarea>
            </p>
            <p class="en-us">
                <label style="height: 130px; line-height: 130px;">说明(En)：</label><textarea rows="5" cols="30" name="CoContentEn"></textarea>
            </p>
        </form>
    </div>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="ScriptContent" runat="server">
    <script type="text/javascript">
        $(document).ready(function () {
            var tableList = $("#table_list").datagrid({
                url: 'Handle/Term/GetListJson.aspx',
                columns: [[
                             { title: 'Id', field: 'id', width: 20, align: 'center', checkbox: true },
                             { title: '名称', field: 'CoName', width: 150, align: 'center', sortable: true },
                             { title: '名称(En)', field: 'CoNameEn', width: 150, align: 'center', sortable: true },
                             { title: '序号', field: 'CoSort', width: 80, align: 'center', sortable: true },
                             { title: '日期', field: 'CoDate', width: 180, align: 'center', sortable: true },
                            {
                                title: '修改', field: 'OpEdit', width: 80, align: 'center', formatter: function (value, rec) {
                                    return '<a href="javascript:void(0);" mce_href="#" onclick="edit(\'' + rec.id + '\')">修改</a> ';
                                }
                            },
                            {
                                title: '删除', field: 'OpDelete', width: 80, align: 'center', formatter: function (value, rec) {
                                    return '<a href="javascript:void(0);" mce_href="#" onclick="del(\'' + rec.id + '\')">删除</a> ';
                                }
                            }
                ]],
                toolbar: [{
                    text: '添加',
                    iconCls: 'icon-add',
                    handler: function () {
                        add();
                    }
                }, '-', {
                    text: '修改',
                    iconCls: 'icon-edit',
                    handler: function () {
                        var selectData = $('#table_list').datagrid('getSelected');
                        if (selectData == null) {
                            $.messager.show({
                                title: '提示',
                                msg: '请选择要修改记录！',
                                timeout: 5000,
                                showType: 'fade'
                            });
                        } else {
                            edit(selectData.id);
                        }
                    }
                }, '-', {
                    text: '查找',
                    iconCls: 'icon-search',
                    handler: function () {
                        $('#search').dialog("open");
                    }
                }, '-', {
                    text: '删除',
                    iconCls: 'icon-remove',
                    handler: function () {
                        var selectData = $('#table_list').datagrid('getSelected');
                        if (selectData == null) {
                            $.messager.show({
                                title: '提示',
                                msg: '请选择要删除记录！',
                                timeout: 5000,
                                showType: 'fade'
                            });
                        } else {
                            del(selectData.id);
                        }
                    }
                }]
            });
            $('#add').dialog({
                title: '添加',
                iconCls: 'icon-add',
                width: 750,
                buttons: [{
                    text: '保存',
                    iconCls: 'icon-ok',
                    handler: function () {
                        addSave();
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#add').dialog('close');
                    }
                }]
            });
            $('#edit').dialog({
                title: '修改',
                iconCls: 'icon-edit',
                width: 750,
                buttons: [{
                    text: '保存',
                    iconCls: 'icon-ok',
                    handler: function () {
                        editSave();
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#edit').dialog('close');
                    }
                }]
            });
            $('#search').dialog({
                title: '检索',
                width: 400,
                closed: true,
                buttons: [{
                    text: '查找',
                    iconCls: 'icon-ok',
                    handler: function () {
                        tableList.datagrid("reload", $('#search_form').serializeObject());
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#search').dialog('close');
                    }
                }]
            });
        });
        //获取文章详细
        edit = function edit(id) {
            if (id == null || id == undefined) {
                var row = $('#table_list').datagrid('getSelected');
                if (!row || row.length == 0) {
                    $.messager.show({
                        title: '提示',
                        msg: '请选择要修改记录！',
                        timeout: 5000,
                        showType: 'fade'
                    });
                    return;
                } else {
                    id = row.id;
                }
            }
            $('#edit_form').form('load', 'Handle/Term/GetDetailJson.aspx?id=' + id);
            $('#edit').dialog("open");
        };
        add = function add() {
            $('#add_form')[0].reset();
            $('#add').dialog("open");
        };
        search = function search() {
            $('#search').dialog("open");
        };
        function del(id) {
            if (id == null || id == undefined) {
                var row = $('#table_list').datagrid('getSelected');
                if (!row || row.length == 0) {
                    $.messager.show({
                        title: '提示',
                        msg: '请选择要删除的数据！',
                        timeout: 5000,
                        showType: 'fade'
                    });
                    return;
                } else {
                    id = row.id;
                }
            }
            $.messager.confirm("提示", "确认删除?", function (b) {
                if (b) {
                    $.ajax({
                        type: "POST",
                        url: "Handle/Term/Delete.aspx",
                        data: { id: id },
                        success: function (msg) {
                            $.messager.show({
                                title: '提示',
                                msg: msg.message,
                                timeout: 5000,
                                showType: 'fade'
                            });
                            if (msg.state)
                                $("#table_list").datagrid("reload");
                        },
                        error: function () {
                            $.messager.show({
                                title: '提示',
                                msg: '删除失败！',
                                timeout: 5000,
                                showType: 'fade'
                            });
                        }
                    });
                }
            });
        }
        function addSave() {
            $.ajax({
                type: "POST",
                url: "Handle/Term/Add.aspx",
                data: $('#add_form').serialize(),
                success: function (msg) {
                    $.messager.show({
                        title: '提示',
                        msg: msg.message,
                        timeout: 5000,
                        showType: 'fade'
                    });
                    if (msg.state) {
                        $("#table_list").datagrid("reload");
                        $('#add_form')[0].reset();
                    }
                },
                error: function () {
                    $.messager.show({
                        title: '提示',
                        msg: '保存失败！',
                        timeout: 5000,
                        showType: 'fade'
                    });
                }
            });
        }
        function editSave() {
            $.ajax({
                type: "POST",
                url: "Handle/Term/Edit.aspx",
                data: $('#edit_form').serialize(),
                success: function (msg) {
                    $.messager.show({
                        title: '提示',
                        msg: msg.message,
                        timeout: 5000,
                        showType: 'fade'
                    });
                    if (msg.state)
                        $("#table_list").datagrid("reload");
                },
                error: function () {
                    $.messager.show({
                        title: '提示',
                        msg: '保存失败！',
                        timeout: 5000,
                        showType: 'fade'
                    });
                }
            });
        }
    </script>
</asp:Content>
